package dao

import (
	"hft/Http/Models/request"

	"gorm.io/gorm"
)

type GetFiles struct{}

func (g *GetAccount) GetFileList(PID int, link string, paginate *request.FilesListInfo, db *gorm.DB) func(db *gorm.DB) *gorm.DB {
	var match string
	if paginate.FileTypes == "" {
		match = "[\\s\\S]*"
	} else if paginate.FileTypes == "video" {
		match = "(mp4|mov|avi)"
	} else if paginate.FileTypes == "image" {
		match = "(jpg|png|jpeg|gif|webp)"
	}
	return func(db *gorm.DB) *gorm.DB {
		return db.Where("link LIKE ?", link).Where("type REGEXP ?", match).Scopes(Paginate(Page(paginate.Page), db)).Select("name,url,size,type,id,create_time,cover")
	}
}

var GetFilesDao = new(GetFiles)
